package com.hp.controller;

import com.hp.entity.User;
import com.hp.service.UserService;
import com.hp.util.JsonData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/login")
    @ResponseBody
    public Object login(User user, HttpServletRequest request) {
        user = userService.login(user);
        if (user != null) {
            request.getSession().setAttribute("user", user);
            return JsonData.buildSuccess(200);
        } else {
            return JsonData.buildError("账号密码错误！");
        }
    }

}